﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Dictionary
{


    public class Program
    {
        static Dictionary<string, Logger> loggreDic;
        static object loggerDicLocker = new object();

        internal static Dictionary<string, Logger> LoggreDic { get => loggreDic; set => loggreDic = value; }

        public static void Main()
        {
            LoggreDic = new Dictionary<string, Logger>();
            for (int i = 0; i < 100; i++)
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    try
                    {
                        var logger = GetLogger("AAA");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine(string.Format("第{0}个线程出现问题", o));
                    }

                }, i);
            }
            Console.ReadKey();
        }

        static Logger GetLogger(string cmdId)
        {
            if (!LoggreDic.ContainsKey(cmdId))
            {
                LoggreDic.Add(cmdId, LogManager.GetLogger(string.Format("AAA.{0}", cmdId)));
            }
            return LoggreDic[cmdId];
        }
    }


}
